package com.cryptape.cita_wallet.jpush;

import android.text.TextUtils;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.MapUtils;
import com.cryptape.cita_wallet.CytonApplication;
import com.cryptape.cita_wallet.activity.EntrustNewActivity;
import com.cryptape.cita_wallet.item.Wallet;
import com.cryptape.cita_wallet.language.MultiLanguageUtil;
import com.cryptape.cita_wallet.net.request.HttpRequestMode;
import com.cryptape.cita_wallet.service.http.TokenService;
import com.cryptape.cita_wallet.util.RSAUtils;
import com.cryptape.cita_wallet.util.db.DBWalletUtil;
import com.cryptape.cita_wallet.util.db.SharePrefUtil;

import java.util.List;
import java.util.Map;

public class PushManager {

    private static PushManager instance;

    public static PushManager getInstance() {
        if (instance == null) {
            instance = new PushManager();
        }
        return instance;
    }

    public void bindPush() {
        if (TextUtils.isEmpty(CytonApplication.getInstance().registrationid)) {
            return;
        }
        List<Wallet> wallets = DBWalletUtil.getAllWallet(CytonApplication.getInstance());
        if (wallets == null || wallets.size() == 0) {
            return;
        }
        for (Wallet wallet : wallets) {
            String isSave = SharePrefUtil.getString(wallet.address);
            if (TextUtils.isEmpty(isSave)) {
                try {
                    Map params = MapUtils.newHashMap();
                    params.put("address", wallet.address);
                    params.put("registrationId", CytonApplication.getInstance().registrationid);
                    params.put("status", "0");
                    params.put("type", "1");
                    String jsonData = GsonUtils.toJson(params);
                    String content = RSAUtils.encrypt(jsonData);
//                    HttpRequestMode.getBindRegistration(CytonApplication.getInstance(), content, true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
